package com.cn.springcloudwechat.controller.vaccine.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.cn.springcloudwechat.common.ajax.AjaxRes;
import com.cn.springcloudwechat.common.mybatis.Page;
import com.cn.springcloudwechat.common.utils.base.Const;
import com.cn.springcloudwechat.model.YmChildrenOrderVaccination;
import com.cn.springcloudwechat.model.YmUserChild;
import com.cn.springcloudwechat.model.vaccine.YmVaccine;
import com.cn.springcloudwechat.model.vaccine.YmVaccineTypeWithBLOBs;
import com.cn.springcloudwechat.service.vaccine.vaccineService.VaccineService;

@RestController
@RequestMapping("/vaccine")
public class VaccineController {

	@Autowired
	VaccineService vaccineService;
	
	
	/**
	 * 疫苗类型的发布(疫苗的类型(详情))
	 * 
	 * @param YmVaccineTypeWithBLOBs ymVaccineTypeWithBLOBs
	 *           
	 * @return SUCC
	 */
	@RequestMapping("/insertVaccineType")
	public AjaxRes insertVaccineType(AjaxRes ajaxRes,YmVaccineTypeWithBLOBs ymVaccineTypeWithBLOBs,@RequestParam(value = "parameter[]",required = false) String[] parameter){
	    try {
	    	this.vaccineService.insertVaccineTypeSer(ymVaccineTypeWithBLOBs,parameter);
	        ajaxRes.setSucceed(Const.SAVE_SUCCEED);
	    }catch (Exception e){
	        ajaxRes.setFailMsg(e.getMessage());
	    }
	    return ajaxRes;
	}
	
	/**
	 * 修改疫苗及关联疫苗(包括详情)
	 * 
	 * @param YmVaccineTypeWithBLOBs ymVaccineTypeWithBLOBs
	 *           
	 * @return SUCC
	 */
	@RequestMapping("/updateVaccineType")
	public AjaxRes updateVaccineType(AjaxRes ajaxRes,YmVaccineTypeWithBLOBs ymVaccineTypeWithBLOBs,@RequestParam("parameter[]") String[] parameter){
	    try {
	    	this.vaccineService.updateVaccineTypeSer(ymVaccineTypeWithBLOBs,parameter);
	        ajaxRes.setSucceed(Const.UPDATE_SUCCEED);
	    }catch (Exception e){
	        ajaxRes.setFailMsg(e.getMessage());
	    }
	    return ajaxRes;
	}
	
	/**
	 * 疫苗类型的查询(配置周岁疫苗的时候使用(管理端))
	 * 
	 * @param YmVaccineTypeWithBLOBs ymVaccineTypeWithBLOBs
	 *           
	 * @return List<YmVaccineTypeWithBLOBs>
	 */
	@RequestMapping("/queryVaccineType")
	public AjaxRes queryVaccineType(AjaxRes ajaxRes,YmVaccineTypeWithBLOBs ymVaccineTypeWithBLOBs,Page<Object> page){
	    try {
	   // 	List<YmVaccineTypeWithBLOBs> ymVaccineTypes= this.vaccineService.queryVaccineTypeSer(ymVaccineTypeWithBLOBs,page);
	    	Page<Object> ymVaccineTypes= this.vaccineService.queryVaccineTypeSer(ymVaccineTypeWithBLOBs,page);
	    	ajaxRes.setSucceed(ymVaccineTypes,Const.DATA_SUCCEED);
	    }catch (Exception e){
	        ajaxRes.setFailMsg(e.getMessage());
	    }
	    return ajaxRes;
	}

	   /**
		 * 疫苗的发布(疫苗的类型(详情),疫苗的关联参数)
		 * 
		 * @param YmVaccine ymVaccine,String[] parameter
		 *           
		 * @return SUCC
		 */
	@RequestMapping("/insertVaccine")
    public AjaxRes insertVaccine(AjaxRes ajaxRes,YmVaccine ymVaccine/*,String[] parameter*/){
        try {
        	this.vaccineService.insertVaccineSer(ymVaccine/*,parameter*/);
            ajaxRes.setSucceed(Const.SAVE_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
	
	/**
	 * 疫苗周岁的详情查询(*某个疫苗的详情查询(客户端))
	 * 
	 * @param YmVaccine ymVaccine
	 *           
	 * @return List<YmVaccine>
	 */
	@RequestMapping("/queryVaccine")
	public AjaxRes queryVaccine(AjaxRes ajaxRes,YmVaccine ymVaccine,Page<Object> page){
	    try {
	    //	List<YmVaccine> YmVaccines = this.vaccineService.queryVaccineSer(ymVaccine);
	    	Page<Object> YmVaccines= this.vaccineService.queryVaccineSer(ymVaccine,page);
	        ajaxRes.setSucceed(YmVaccines,Const.DATA_SUCCEED);
	    }catch (Exception e){
	        ajaxRes.setFailMsg(e.getMessage());
	    }
	    return ajaxRes;
	}
	
	/**
	 * 疫苗关联查询(包括详情)*找到某个疫苗所有所有关联疫苗(管理端)
	 * 
	 * @param YmVaccine YmVaccine(vaccineTypeId)
	 *           
	 * @return List<YmVaccineTypeWithBLOBs>
	 */
	@RequestMapping("/queryVaccineRelevanceDetailPc")
	public AjaxRes queryVaccineRelevanceDetailPc(AjaxRes ajaxRes,YmVaccine ymVaccine){
	    try {
	    	List<YmVaccineTypeWithBLOBs> YmVaccines = this.vaccineService.queryVaccineRelevanceDetailPcSer(ymVaccine);
	        ajaxRes.setSucceed(YmVaccines,Const.DATA_SUCCEED);
	    }catch (Exception e){
	        ajaxRes.setFailMsg(e.getMessage());
	    }
	    return ajaxRes;
	}
	
	/**
	 * 疫苗关联查询(包括详情)*找到某个疫苗所有所有关联疫苗(客户端)
	 * 
	 * @param YmVaccine YmVaccine
	 *           
	 * @return List<YmVaccine>
	 */
	@RequestMapping("/queryVaccineRelevanceDetail")
	public AjaxRes queryVaccineRelevanceDetail(AjaxRes ajaxRes,YmVaccine ymVaccine,@RequestParam("vaccines[]") String[] vaccines){
	    try {
	    	List<YmVaccine> YmVaccines = this.vaccineService.queryVaccineRelevanceDetailSer(vaccines);
	        ajaxRes.setSucceed(YmVaccines,Const.DATA_SUCCEED);
	    }catch (Exception e){
	        ajaxRes.setFailMsg(e.getMessage());
	    }
	    return ajaxRes;
	}
	
	/**
	 * 接种证查询(移动端)
	 * 
	 * @param age(可有可无的查询条件*年龄段)
	 *           
	 * @return List<YmVaccine>
	 */
	@RequestMapping("/queryVaccineInoculationPlan")
	public AjaxRes queryVaccineInoculationPlan(AjaxRes ajaxRes,String age,YmUserChild ymUserChild){
	    try {
	    	List<YmVaccine> weekYearPlans = this.vaccineService.queryVaccineInoculationPlanSer(age,ymUserChild);
	        ajaxRes.setSucceed(weekYearPlans,Const.DATA_SUCCEED);
	    }catch (Exception e){
	        ajaxRes.setFailMsg(e.getMessage());
	    }
	    return ajaxRes;
	}
	
	/**
	 * 接种历史(剂次)查询(移动端*接种证点击进入查询)
	 * 
	 * @param vaccineId,parentId
	 *           
	 * @return List<YmVaccine>
	 */
	@RequestMapping("/queryVaccineHistoryPlan")
	public AjaxRes queryVaccineHistoryPlan(AjaxRes ajaxRes,Long vaccineTypeId,Long parentId,Long childrenId){
	    try {
	    	List<YmVaccine> weekYearPlans = this.vaccineService.queryVaccineHistoryPlanSer(vaccineTypeId,parentId,childrenId);
	        ajaxRes.setSucceed(weekYearPlans,Const.DATA_SUCCEED);
	    }catch (Exception e){
	        ajaxRes.setFailMsg(e.getMessage());
	    }
	    return ajaxRes;
	}
	
	/**
	 * 新增历史疫苗(管理端)*需要改进
	 * 
	 * @param YmChildrenOrderVaccination YmChildrenOrderVaccination
	 *           
	 * @return List<YmVaccine>
	 */
	@RequestMapping("/insertYmChildrenOrderVaccination")
    public AjaxRes insertYmChildrenOrderVaccination(AjaxRes ajaxRes,YmChildrenOrderVaccination YmChildrenOrderVaccination){
        try {
        	this.vaccineService.insertYmChildrenOrderVaccinationSer(YmChildrenOrderVaccination);
            ajaxRes.setSucceed(Const.SAVE_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
    }
	
	/**
	 * 查询历史疫苗(移动端)
	 * 
	 * @param 
	 *           
	 * @return List<YmVaccine>
	 */
	@RequestMapping("/queryVaccineHistoryPlanAll")
	public AjaxRes queryVaccineHistoryPlanAll(AjaxRes ajaxRes,Long childrenId){
	    try {
	    	List<YmVaccine> weekYearPlans = this.vaccineService.queryVaccineHistoryPlanAllSer(childrenId);
	        ajaxRes.setSucceed(weekYearPlans,Const.DATA_SUCCEED);
	    }catch (Exception e){
	        ajaxRes.setFailMsg(e.getMessage());
	    }
	    return ajaxRes;
	}
	
	/**
	 * 接种参考查询(移动端)*自费和非自费(isCharge)
	 * 
	 * @param 
	 *           
	 * @return List<YmVaccine>
	 */
	@RequestMapping("/queryInoculationConsult")
	public AjaxRes queryInoculationConsult(AjaxRes ajaxRes){
	    try {
	    	List<YmVaccine> weekYearPlans = this.vaccineService.queryInoculationConsultSer();
	        ajaxRes.setSucceed(weekYearPlans,Const.DATA_SUCCEED);
	    }catch (Exception e){
	        ajaxRes.setFailMsg(e.getMessage());
	    }
	    return ajaxRes;
	}
}
